package utils

import (
	"fmt"
	"sync"
	"time"
)

var requestId = 1
var request4Id = 1

// 初始化锁
var lock = new(sync.RWMutex)

func GetRandomId() int {
	lock.Lock()
	if requestId > 20000 {
		requestId = 1
	} else {
		requestId++
	}
	lock.Unlock()
	return requestId
}

func Get4RandomId() int {
	lock.Lock()
	if requestId > 9999 {
		requestId = 1
	} else {
		requestId++
	}
	lock.Unlock()
	return requestId
}

func GetScanId() string {
	getYear := time.Now().Format("2006") //获取年
	getMonth := time.Now().Format("01")  //获取月
	getDay := time.Now().Format("02")    //获取日
	hour := time.Now().Format("15")
	min := time.Now().Format("04")
	second := time.Now().Format("05")
	randomId := GetRandomId()
	randomIdStr := fmt.Sprintf("%05d", randomId)

	return fmt.Sprintf("%s%s%s%s%s%s%s", getYear, getMonth, getDay, hour, min, second, randomIdStr)
}

func Get4SequenceId() string {
	getYear := time.Now().Format("2006") //获取年
	getMonth := time.Now().Format("01")  //获取月
	getDay := time.Now().Format("02")    //获取日
	hour := time.Now().Format("15")
	min := time.Now().Format("04")
	second := time.Now().Format("05")
	randomId := Get4RandomId()
	randomIdStr := fmt.Sprintf("%04d", randomId)

	return fmt.Sprintf("%s%s%s%s%s%s%s", getYear, getMonth, getDay, hour, min, second, randomIdStr)
}
